package com.cwz.taculture.controller.index;

import com.cwz.taculture.pojo.CommodityPojo;
import com.cwz.taculture.service.index.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * index页面controller
 */
//@Controller
@CrossOrigin
@RestController
public class IndexController {
    /**
     * 自动注入
     */
    @Autowired
    private IndexService index_service;
//    查询所有首页数据
    @RequestMapping("SelCommodity")
    public List SelCommodity(Model model){
 //       model.addAttribute("index_list",index_service.SelCommodity());
        List<CommodityPojo> list = index_service.SelCommodity();
       return list;
 //      return "index";
    }
//    点击购买带值跳转
    @RequestMapping("SelCommodityBycPiture/{commodityPicture}")
    public CommodityPojo SelCommodityBycPiture(@PathVariable("commodityPicture") String commodityPicture, Model model){
        model.addAttribute("index_list",index_service.SelCommodityBycPiture(commodityPicture));
        CommodityPojo pictureList = index_service.SelCommodityBycPiture(commodityPicture);
        return pictureList;
    }

}
